import java.util.HashMap;
import java.util.Objects;

public class HashBuck {
    static class Node{
        public int key;
        public int val;
        public Node nxet;

        public Node(int val, int key) {
            this.val = val;
            this.key = key;
        }

    }
    public Node[] array;
    public int usedSize;
    public static final float DEFAULT_LOAD_FACTOR= 0.75F;

    public HashBuck(int usedSize, Node[] array) {
        this.usedSize = 0;
        this.array = new Node[10];
    }
    public void put(int key,int val){
        Node node = new Node(key,val);
        int index=key%array.length;
        Node cur=array[index];
        while (cur!=null){
        if (cur.key==key){
            cur.val=val;
            return;
        }
        cur=cur.nxet;
        }
        node.nxet=array[index];
        array[index]=node;
        usedSize++;
        if (loadFactor() >= DEFAULT_LOAD_FACTOR){
            grow();
        }

    }
    private  float loadFactor(){
        return usedSize*1.0f/array.length;
    }
    private void grow(){
        Node[] newArray=new Node[2*array.length];
        for (int i = 0; i < array.length; i++) {
            Node cur = array[i];
            while (cur!=null) {
                Node curNext=cur.nxet;
                int index = cur.key % newArray.length;
                cur.nxet = newArray[index];
                newArray[index] = cur;
                cur=curNext;
            }
        }
        this.array=newArray;
    }
    public int get(int key) {
        int index = key % array.length;
        Node cur = array[index];
        while (cur != null) {
            if (cur.key == key) {
                return cur.val;
            }
            cur = cur.nxet;
        }
        return -1;
    }
   static class Person{
        String id;

        public Person(String id) {
            this.id = id;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "id='" + id + '\'' +
                    '}';
        }

        @Override
        public boolean equals(Object o) {
            if (o == null || getClass() != o.getClass()) return false;
            Person person = (Person) o;
            return Objects.equals(id, person.id);
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(id);
        }
    }

    public static void main(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");
//        HashMap<Person,String> hashMap=new HashMap<>();
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }
}
